import { Component } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { OssFileUploadComponent } from './upload/upload.component';
import { environment } from '@env/environment';
import { SListComponent } from '../../common/list/slist.component';
import { OssFile } from '@api/oss/model/ossFile.model';
import { OssFileService } from '@api/oss/service/ossFile.service';

@Component({
  selector: 'app-sys-file',
  templateUrl: '../../common/list/list.component.html',
})
export class OssFileComponent extends SListComponent<OssFile, String> {
  constructor(public http: _HttpClient, public modal: ModalHelper, public ossFileService: OssFileService, public msgSrv: NzMessageService) {
    super(http, modal, ossFileService, msgSrv, OssFileUploadComponent);

    this.searchSchema = {
      properties: {
        id: {
          type: 'string',
          title: '主键ID',
        },
        batchId: {
          type: 'string',
          title: '批次ID',
        },
        name: {
          type: 'string',
          title: '名称',
        },
      },
    };

    this.columns = [
      { title: 'ID', index: 'id', type: 'checkbox' },
      { title: 'ID', index: 'id' },
      { title: '批次ID', index: 'batchId' },
      { title: '名称', index: 'name' },
      { title: '扩展名', index: 'extName' },
      { title: '类型', index: 'contentType' },
      { title: '路径', index: 'path' },
      { title: '大小', index: 'size' },
      { title: '仓库', index: 'store' },
      { title: 'MD5', index: 'md5' },
      { title: '创建时间', index: 'createdDate', type: 'date' },
      { title: '创建人', index: 'createdBy' },
      {
        title: '操作',
        width: 100,
        fixed: 'right',
        buttons: [
          // { text: '查看', click: (item: any) => `/form/${item.id}` },
          {
            icon: 'download',
            type: 'none',
            click: (record: any) => {
              window.location.href = `${environment.SERVER_URL}${environment.oss.ctx}/ossFile/download/${record.id}`;
            },
            tooltip: `下载`,
          },
          {
            tooltip: `删除`,
            icon: 'delete',
            type: 'del',
            pop: {
              title: '是否确定删除?',
              okType: 'danger',
              icon: 'star',
            },
            click: (record, _modal, comp) => this.delete(record, _modal, comp),
          },
        ],
      },
    ];
  }
}
